﻿/*--------------------------------------------------------------------------------
 * Adaptive Intelligence - Foundation Framework Class Library
 * Version 2.00
 * 
 * ZIP I/O Base Class
 * 		Provides a common definition for classes which utilize I/O methods.
 *------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------
 * System Imports
 *------------------------------------------------------------------------------*/
using System;
using System.IO;

namespace Adaptive.Foundation.IO.Zip
{
	/// <summary>
	/// Provides a common definition for classes which utilize I/O methods.
	/// </summary>
	public abstract class ZipIoBase : AiObjectBase, IStorable
	{
		/*--------------------------------------------------------------------------------
		 * Public Events
		 *------------------------------------------------------------------------------*/
		#region Public Events
		/// <summary>
		/// Occurs when an I/O read exception is encountered. 
		/// </summary>
		public event IoExceptionEventHandler ReadException;
		/// <summary>
		/// Occurs when an I/O write exception is encountered.
		/// </summary>
		public event IoExceptionEventHandler WriteException;
		#endregion

		/*--------------------------------------------------------------------------------
		 * Constructor / Dispose / Destructor Methods
		 *------------------------------------------------------------------------------*/
		#region Constructor / Dispose / Destructor Methods
		/// <summary>
		/// Initializes a new instance of the <see cref="ZipIoBase" /> class.
		/// </summary>
		/// <remarks>
		/// This is the default constructor.
		/// </remarks>
		protected ZipIoBase()
			: base()
		{
		}
		#endregion

		/*--------------------------------------------------------------------------------
		 * Protected Method Events
		 *------------------------------------------------------------------------------*/
		#region Protected Method Events
		/// <summary>
		/// Raises the <see cref="E:ReadException" /> event.
		/// </summary>
		/// <param name="e">The <see cref="IoExceptionEventArgs" /> instance containing the event data.</param>
		protected virtual void OnReadException(IoExceptionEventArgs e)
		{
			if (ReadException != null)
				ReadException(this, e);
		}
		/// <summary>
		/// Raises the <see cref="E:WriteException" /> event.
		/// </summary>
		/// <param name="e">The <see cref="IoExceptionEventArgs" /> instance containing the event data.</param>
		protected virtual void OnWriteException(IoExceptionEventArgs e)
		{
			if (WriteException != null)
				WriteException(this, e);
		}
		#endregion

		/*--------------------------------------------------------------------------------
		 * Public Methods / Functions
		 *------------------------------------------------------------------------------*/
		#region Public Methods / Functions
		/// <summary>
		/// Reads the content of the object from the underlying stream.
		/// </summary>
		/// <param name="reader">
		/// An open <see cref="BinaryReader"/> used to read the data content.
		/// </param>
		/// <returns>
		/// <b>true</b> if the operation is successful; otherwise, returns <b>false</b>.
		/// </returns>
		public abstract bool Load(BinaryReader reader);
		/// <summary>
		/// Writes the content of the object to the underlying stream.
		/// </summary>
		/// <param name="writer">
		/// An open <see cref="BinaryWriter"/> used to write the data content.
		/// </param>
		/// <returns>
		/// <b>true</b> if the operation is successful; otherwise, returns <b>false</b>.
		/// </returns>
		public abstract bool Save(BinaryWriter writer);
		#endregion
	}
}
